﻿Partial Public Class ClassHandler

    Private Sub Button_Clicks(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click, Button2.Click, Button3.Click
        Me.lbEventsLog.Items.Add("Instance Handler: " & e.Source.ToString)
    End Sub

    'using instance method 
    Private Sub Class_Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Me.lbEventsLog.Items.Clear()
        Me.lbEventsLog.Items.Add("Class Handler: " & e.Source.ToString)
    End Sub

    Private Sub ClassHandler_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        'no way to unhook class handlers
        EventManager.RegisterClassHandler(GetType(Button), Button.ClickEvent, New RoutedEventHandler(AddressOf Class_Button_Click))
    End Sub


    'using shared method 

    'Private Shared Sub Class_Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    '    Me.lbEventsLog.Items.Clear()
    '    Me.lbEventsLog.Items.Add("Button: " & e.Source.ToString)
    'End Sub

    'Shared Sub New()
    '    'no way to unhook class handlers
    '    EventManager.RegisterClassHandler(GetType(Button), Button.ClickEvent, New RoutedEventHandler(AddressOf Class_Button_Click))
    'End Sub
End Class
